package iot.wlink.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.wlink.bean.entity.DeviceTemplate;
import iot.wlink.bean.vo.DeviceTemplateVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author : willian fu
 * @date : 2021/8/23
 */
public interface DeviceTemplateMapper extends BaseMapper<DeviceTemplate> {

    /**
     * 查询模板列表
     * @return 模板列表
     */
    @Select("SELECT dt.tid, dt.name, dt.protocol, dt.avatar, dt.device_type, IFNULL(dv.device_num,0) device_num, dt.remark, dt.updated\n" +
            "FROM device_template dt LEFT JOIN (SELECT tid, count(0) device_num FROM DEVICE GROUP BY tid) dv ON dt.tid = dv.tid")
    List<DeviceTemplateVo> selectTemplateList();


}
